import { publicProcedure, router } from "../trpc";
import z, { string } from "zod"

export const appRouter = router({
    //首页
    index: publicProcedure
        .input(z.object({ name: string().optional() }).optional())
        .output(z.object({
            msg: string(),
            name: string(),
            auth: string()
        }))
        .meta({
            openapi: {
                method: 'GET',
                path: '/',
                summary: "首页",
                description: "详细描述",
                tags: ["首页类"],
                protect: true,
                example: {
                    request: {
                        name: "请求名称"
                    },
                    response: {
                        msg: "信息",
                        name: "名称",
                        auth: "auth"
                    }
                }
            }
        })
        .query(async (opt) => {
            return {
                msg: "成功:服务已经启动!",
                name: opt.input?.name ?? "[未定义]",
                auth: opt.ctx.user ?? "[未定义]"
            }
        }),

    //
    ask: publicProcedure
        .input(z.string())
        .mutation(async (opt) => {
            let name = opt.input;
            return "hello " + name
        })
});

export type AppRouter = typeof appRouter;
